﻿<template>
	<el-dialog :title="!dataForm.id ? '新建' : '编辑'" :close-on-click-modal="false" :visible.sync="visible"
		class="SHZY-dialog SHZY-dialog_center" lock-scroll width="600px">
		<el-row :gutter="15" class="">
			<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right"
				:rules="rules">
				<el-col :span="24">
					<el-form-item label="IP 地址" prop="ipAddress">
						<el-input v-model='dataForm.ipAddress' placeholder='请输入' clearable :style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="名称" prop="name">
						<el-input v-model='dataForm.name' placeholder='请输入' clearable :style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
		
				<el-col :span="24">
					<el-form-item label="有效标志" prop="enabledMark">
						<el-switch v-model="dataForm.enabledMark" 
							:active-value = 1 :inactive-value = 0>
						</el-switch>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="备注" prop="remark">
						<el-input v-model='dataForm.remark' placeholder='请输入' clearable :style='{ "width": "100%" }'  type="textarea" maxlength="200" show-word-limit :rows="3">
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
import cameraManage from '@/api/q1/business/cameraManage';
export default {
	components: {},
	props: [],
	data() {
		return {
			btnLoading: false,
			loading: false,
			visible: false,
			dataForm: {
				id: '',
				ipAddress: undefined,
				name: undefined,
				remark: undefined,
				creatorUserId: undefined,
				creatorTime: undefined,
				enabledMark: 1,
			},
			rules: {

				ipAddress: [
					{
						required: true,
						message: '请输入IP地址',
						trigger: "blur"
					}
				],
				name: [
					{
						required: true,
						message: '请输入名称',
						trigger: "blur"
					}
				],
				enabledMark: [
					{
						required: true,
						message: '请选择是否有效',
						trigger: "blur"
					}
				],
			},
		}
	},
	computed: {},
	watch: {},
	created() {
	},
	mounted() {
	},
	methods: {
		goBack() {
			this.$emit('refresh')
		},
		init(id) {
			this.dataForm.id = id || 0;
			this.visible = true;
			this.$nextTick(() => {
				this.$refs['elForm'].resetFields();
				if (this.dataForm.id) {

					cameraManage.qmsbasecameraipbyid(this.dataForm.id).then(res =>{
						this.dataForm = res.data;

					})
				}
			});
			this.$store.commit('generator/UPDATE_RELATION_DATA', {})
		},
		dataFormSubmit() {
			this.$refs['elForm'].validate((valid) => {
				if (valid) {
					this.btnLoading = true;
					if (!this.dataForm.id) {

						cameraManage.addqmsbasecameraip(this.dataForm).then(res => {
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.btnLoading = false;
									this.visible = false,
										this.$emit('refresh', true)
								}
							})

						})
					} else {

						cameraManage.updateqmsbasecameraip(this.dataForm).then(res => {
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.btnLoading = false;
									this.visible = false
									this.$emit('refresh', true)
								}
							})

						})
					}
				}
			})
		},
	}
}
</script>
